package post_to_in_pkg.node;

public class If_node extends Node{
	private OperandNode Condition;
	private Blocks statement;
	public String code="";
	public If_node(OperandNode condition,Blocks stmts) {
		Condition=condition;
		statement=stmts;
		statement.setIndent(true);
	}
	
	public String toString() {
		String s="\n";
		s=s+"if ("+Condition.toString()+" ) {"+statement.toString()+" }";
		return s;
	}
	
	
	public boolean isReturnVoid() {
		return true;
	}
	
	public boolean isTempNode() {
		return false;
	}

	@Override
	public boolean hasChild() {
		// TODO Auto-generated method stub
		return statement.hasChild();
	}

	@Override
	public String[] generateCodes() {
	// TODO Auto-generated method stub

		String[] condition_codeVector=Condition.generateCodes();
		String If_stmt_code;
		String[] If_node_code=new String[2];
		if(Condition.hasChild()){
			If_node_code[0]="\n"+condition_codeVector[0];
		}
		If_stmt_code=statement.generateCodes()[1];
		code+="\n";
		code=code+"if("+condition_codeVector[1]+") {\n"+
				If_stmt_code+
				"\n}";
		If_node_code[1]=code;
		return If_node_code;
//		if(Condition.hasChild()){
//			code=code+"\n"+Condition.generateCodes();
//		}
//		code+="\n";
//		code=code+"if("+Condition.toString()+") {"+"\n"
//				+statement.generateCodes()
//				+"\n}";
//		return code;
	}

//	@Override
//	public void printChild(StringBuffer content) {
//		// TODO Auto-generated method stub
//		StringBuffer str_if_buf=new StringBuffer();
//		if(Condition.hasChild()) {
//			Condition.printChild(content);
//		}
//		statement.printChild(str_if_buf);
//		content.append(
//				"\nif("+Condition.getName()+"){\n"+
//				 str_if_buf.toString()+
//				 "\n}\n");
//
//	}


}
